<%-- 
    Document   : index
    Created on : Jan 18, 2013, 8:11:14 PM
    Author     : pcsijbug
--%>

<%@page import="beans.BeanProformaDetalle"%>
<%@page import="beans.BeanProformaCabecera"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <script>
            //aqui meto javascript
            function abrirBusqueda() {
                var contexto = "<%= request.getContextPath()%>";
                var nombre = document.getElementById("txtNombre").value;
                if (nombre = '') {
                    alert("Por favor ingresa un nombre.");
                    return false;
                } else {

                    document.form1.action = contexto + "/buscar";
                    document.form1.submit();
                    return true;
                }
            }

            function  GrabarProforma() {
                var contexto = "<%= request.getContextPath()%>";
                document.form1.action = contexto + "/registrar";
                document.form1.submit();
                return true;
            }
        </script>
    </head>
    <body>
        <div id="contenedor">
            <form id="form1" name="form1" method="post" action="">
                <table width="495" border="0">
                    <tr>
                        <td width="91">Proforma:<br /></td>
                        <td width="144">
                            <label>
                                <input type="text" name="textfield" disabled="" value="<%= request.getAttribute("IdProforma")%>" />
                            </label>

                        </td>
                        <td width="55">Fecha:</td>
                        <td width="144">
                            <label>
                                <input type="text" name="txtDate" />
                            </label>

                        </td>
                        <td width="39">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>Tipo Doc: </td>
                        <td>
                            <label>
                                <select name="selectDocumento">
                                    <option value="0" selected>Seleccionar</option>
                                    <option value="1">DNI</option>
                                    <option value="2">RUC</option>
                                </select>
                            </label>

                        </td>
                        <td>Nombre / Razon Social : </td>
                        <td><input type="text" name="txtNombre" id="txtNombre"/></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>Tipo Comprobante: </td>
                        <td><select name="selectTipoDocumento">
                                <option value="0" selected>Seleccionar</option>
                                <option value="1">FACTURA</option>
                                <option value="2">BOLETA</option>
                            </select></td>
                        <td>&nbsp;</td>
                        <td><label>
                                <input type="submit" value="Agregar" onclick="javascript:abrirBusqueda();" />
                                <input type="submit" value="Grabar" onclick="javascript:GrabarProforma();" />
                            </label></td>
                        <td><a href="#">Eliminar</a></td>
                    </tr>
                </table>
                <div align="center"></div>
                <table width="505" border="1">
                    <tr>
                        <td width="77"><strong>Seleccionar</strong></td>
                        <td width="47"><strong>Codigo</strong></td>
                        <td width="79"><strong>Descripcion</strong></td>
                        <td width="144"><strong>Cantidad</strong></td>
                        <td width="54"><strong>Precio Unitario</strong> </td>
                        <td width="64"><strong>Subtotal</strong></td>
                    </tr>

                    <%
                        if (session.getAttribute("proforma") != null) {
                            BeanProformaCabecera cabe = (BeanProformaCabecera) session.getAttribute("proforma");

                            List listDetalle = cabe.getListaDetallesProforma();

                            for (int i = 0; i < listDetalle.size(); i++) {
                                BeanProformaDetalle det = (BeanProformaDetalle) listDetalle.get(i);

                    %>
                    <tr>
                        <td><label>
                                <input type="checkbox" name="checkbox<%= i%>" value="checkbox" />
                            </label></td>
                        <td><%=det.getCodigoArancel()%> </td>
                        <td><%=det.getDescripcion()%></td>
                        <td><input type="text" name="textfield222" value="<%=det.getCantidad()%>" /></td>
                        <td><%=det.getPrecioUnitario()%></td>
                        <td><%=det.getSubTotal()%></td>
                    </tr>
                    <% }
                        }%>
                </table>
                <p>&nbsp;</p>
            </form>
        </div>
    </body>
</html>
